<?php
class Boostrap
{
	public $Routes;

	public function __construct($routes)
	{
		$this->Routes = $routes;
	}

	public function Start()
	{
		$params = array();
		
		if(isset($_REQUEST['url'])) 
		{			
			$route = $this->Routes->MatchRoute($_REQUEST['url']);
			
			if($route == null)
			{
				// redirect
				header('Status: 404 Not Found');
				exit;
			}			
						
			$controllerName = $route->ControllerName;
			$actionName = $route->ActionName;
			$urlParams = $route->Param;						
			
			$getParam = $_GET;
			$postParam = $_POST;
			
			$params = array_merge($getParam, $postParam, $urlParams);
		}
		else 
		{
			$controllerName = 'HomeController';
			$actionName = 'Index';
		}
		
		include_once (CONTROLLER.'/'.$controllerName.'.php');
		
		$controller = new $controllerName($params);
		$authencateObject = new Authencate();
		$controller->SetIdentity($authencateObject->CheckLogIn());
		
		$controller->$actionName();
	}
}